/**
 * 
 */
package hu.gbalage.owlforms.impl.style;

import java.net.URI;

import org.semanticweb.owl.model.OWLAnnotation;
import org.semanticweb.owl.model.OWLClass;
import org.semanticweb.owl.model.OWLObject;
import org.semanticweb.owl.model.OWLProperty;
import org.semanticweb.owl.vocab.OWLRDFVocabulary;

import hu.gbalage.owlforms.OWLFormsManager;
import hu.gbalage.owlforms.api.Field;
import hu.gbalage.owlforms.api.Form;
import hu.gbalage.owlforms.api.style.FieldTitleProvider;
import hu.gbalage.owlforms.internal.AnnotationCollector;

/**
 * @author Grill Balazs (balage.g@gmail.com)
 *
 */
public class FieldTitleProviderImpl implements FieldTitleProvider {

	public static final URI labeluri = OWLRDFVocabulary.RDFS_LABEL.getURI();
	
	protected final OWLFormsManager manager;
	
	public FieldTitleProviderImpl(OWLFormsManager manager){
		this.manager = manager;
	}
	
	public String getTitle(Form form) {
		AnnotationCollector collector = manager.getAnnotationCollector();
		
		OWLClass clazz = manager.getDataFactory().getOWLClass(form.getURI());
	
		for (OWLAnnotation<OWLObject> a : collector.collect(clazz,labeluri )){
			return a.getAnnotationValueAsConstant().getLiteral();
		}
		
		return "";
	}
	
	public String getTitle(Field field) {
		AnnotationCollector collector = manager.getAnnotationCollector();
		
		OWLProperty<?, ?> property = field.isPrimitive() ?
				manager.getDataFactory().getOWLDataProperty(field.getURI()) :
				manager.getDataFactory().getOWLObjectProperty(field.getURI());
	
		for (OWLAnnotation<OWLObject> a : collector.collect(property,labeluri )){
			return a.getAnnotationValueAsConstant().getLiteral();
		}
		
		return "";
	}
	
}
